package com.cn.wanxi.service.impl;

import com.cn.wanxi.entity.ProductEntity;
import com.cn.wanxi.mapper.ProductMapper;
import com.cn.wanxi.mapper.SortMapper;
import com.cn.wanxi.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private SortMapper sortMapper;

    @Override
    public List<ProductEntity> findAll(ProductEntity productEntity) {

        return productMapper.findAll(productEntity);
    }

    @Override
    public int getCount(ProductEntity productEntity) {

        return productMapper.getCount(productEntity);
    }

    @Override
    public String del(Integer id) {

        return productMapper.del(id) == 1 ? "success" : "error";
    }

    @Override
    public ProductEntity findById(Integer id) {

        return productMapper.findById(id);
    }

    @Override
    public String edit(ProductEntity productEntity) {

//        int edit = productMapper.edit(productEntity);
//        sortMapper.edit(productEntity);
        return productMapper.edit(productEntity) == 1 ? "success" : "error";
    }

    @Override
    public String add(ProductEntity productEntity) {

        return productMapper.add(productEntity) == 1 ? "success" : "error";
    }
}
